class AdminController < ApplicationController
  skip_before_filter :authorize, :only => [:logout, :login]

  def login
    session[:id] = nil
    if request.post?
      user = Usuario.buscar(params[:login])
      if user
        user = Usuario.autentificar(user, params[:clave])
        if user
          session[:id] = user.id
          uri = session[:original_uri]
          session[:original_uri] = nil
          redirect_to(uri || { :action => "index" , :controller =>:admin})
        else
          @error="Contrasena Invalida"
          flash.now[:notice] = "Login o Contrasena Invalida"
        end
      else
        @error="No existe usuario alguno con dicho login \""+params[:login]+"\" ."
        flash.now[:notice] = "Login o Contrasena Invalida"
      end
    end
  end

  def logout
    session[:id] = nil
    flash[:notice] = "Logged out"
  end

  def index
  end


end
